package Acm;


import java.io.*;
public class AContrastValue {
    public static void main(String[] args) throws IOException {
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        int n = (int) st.nval;

        for (int m = 0; m < n; m++) {
            long sum = 0;
            long count = 0;
            st.nextToken();
            int len = (int) st.nval;
            long pre = 0;
            boolean up = false;
            int count2=0;
            boolean down = false;
            for (int i = 0; i < len; i++) {
                st.nextToken();
                long tmp = (long) st.nval;
                if(i == 0){
                   pre = tmp;
                   continue;
                }
                if(i == 1){
                    if(tmp > pre){
                        up = true;
                    }else if(tmp < pre){
                        down =true;
                    }
                    if(pre!=tmp){
                        count2+=2;
                    }
                }
                if(pre != tmp){
                    count2++;
                }
                if(!up&&!down){
                    if(tmp > pre){
                        up = true;
                    }else if(tmp < pre){
                        down =true;
                    }
                    continue;
                }
                if(tmp > pre && !up){
                    up = true;
                    count++;
                }else if(tmp < pre && !down){
                    count++;
                    down = true;
                }
                pre = tmp;
            }
            if(count2>=2){
                count+= 2;
            }else{
                count = 1;
            }
            System.out.println(count);
        }
    }
}
